package com.gisocn.onemap.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import butterknife.internal.Utils;
import com.gisocn.onemap.interfaces.OnItemClickListener;
import com.gisocn.onemap.model.Download;
import com.gisocn.onemap.sgzx.R;
import com.gisocn.onemap.utils.FormatSizeUtil;
import com.gisocn.onemap.widget.MyProgress;
import java.util.List;

/* loaded from: classes2.dex */
public class ExpandableDownLoadAdapter extends BaseExpandableListAdapter {
    private Context context;
    private List<Download.NewItem> downloadList;
    private OnItemClickListener onChildItemClickListener;
    private OnItemClickListener onGroupItemClickListener;

    @Override // android.widget.ExpandableListAdapter
    public long getChildId(int i, int i2) {
        return i2;
    }

    @Override // android.widget.ExpandableListAdapter
    public long getGroupId(int i) {
        return i;
    }

    @Override // android.widget.ExpandableListAdapter
    public boolean hasStableIds() {
        return true;
    }

    @Override // android.widget.ExpandableListAdapter
    public boolean isChildSelectable(int i, int i2) {
        return true;
    }

    /* loaded from: classes2.dex */
    public class ChildViewHolder_ViewBinding implements Unbinder {
        private ChildViewHolder target;

        public ChildViewHolder_ViewBinding(ChildViewHolder childViewHolder, View view) {
            this.target = childViewHolder;
            childViewHolder.tvTitleChild = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_title, "field 'tvTitleChild'", TextView.class);
            childViewHolder.tvSizeChild = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_size, "field 'tvSizeChild'", TextView.class);
            childViewHolder.tvProgressChild = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_progress, "field 'tvProgressChild'", TextView.class);
            childViewHolder.progressChild = (MyProgress) Utils.findRequiredViewAsType(view, R.id.progress, "field 'progressChild'", MyProgress.class);
            childViewHolder.tvStatusChild = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_offline_download_status, "field 'tvStatusChild'", TextView.class);
            childViewHolder.btnDownloadChild = (TextView) Utils.findRequiredViewAsType(view, R.id.btn_offline_download, "field 'btnDownloadChild'", TextView.class);
        }

        @Override // butterknife.Unbinder
        public void unbind() {
            ChildViewHolder childViewHolder = this.target;
            if (childViewHolder == null) {
                throw new IllegalStateException("Bindings already cleared.");
            }
            this.target = null;
            childViewHolder.tvTitleChild = null;
            childViewHolder.tvSizeChild = null;
            childViewHolder.tvProgressChild = null;
            childViewHolder.progressChild = null;
            childViewHolder.tvStatusChild = null;
            childViewHolder.btnDownloadChild = null;
        }
    }

    /* loaded from: classes2.dex */
    public class GroupViewHolder_ViewBinding implements Unbinder {
        private GroupViewHolder target;

        public GroupViewHolder_ViewBinding(GroupViewHolder groupViewHolder, View view) {
            this.target = groupViewHolder;
            groupViewHolder.layoutAll = (LinearLayout) Utils.findRequiredViewAsType(view, R.id.layout_expand_group_all, "field 'layoutAll'", LinearLayout.class);
            groupViewHolder.ivGroupLeft = (ImageView) Utils.findRequiredViewAsType(view, R.id.iv_expand_group_arrow, "field 'ivGroupLeft'", ImageView.class);
            groupViewHolder.tvGroupName = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_expand_group_title, "field 'tvGroupName'", TextView.class);
            groupViewHolder.tvDownloadAll = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_expand_group_download_all, "field 'tvDownloadAll'", TextView.class);
            groupViewHolder.tvDownloadNumber = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_expand_group_number, "field 'tvDownloadNumber'", TextView.class);
            groupViewHolder.layoutDownloadItemAll = (LinearLayout) Utils.findRequiredViewAsType(view, R.id.layout_offline_download_item_all, "field 'layoutDownloadItemAll'", LinearLayout.class);
            groupViewHolder.tvTitleGroup = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_title, "field 'tvTitleGroup'", TextView.class);
            groupViewHolder.tvSizeGroup = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_size, "field 'tvSizeGroup'", TextView.class);
            groupViewHolder.tvProgressGroup = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_progress, "field 'tvProgressGroup'", TextView.class);
            groupViewHolder.progressGroup = (MyProgress) Utils.findRequiredViewAsType(view, R.id.progress, "field 'progressGroup'", MyProgress.class);
            groupViewHolder.tvStatusGroup = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_offline_download_status, "field 'tvStatusGroup'", TextView.class);
            groupViewHolder.btnDownloadGroup = (TextView) Utils.findRequiredViewAsType(view, R.id.btn_offline_download, "field 'btnDownloadGroup'", TextView.class);
        }

        @Override // butterknife.Unbinder
        public void unbind() {
            GroupViewHolder groupViewHolder = this.target;
            if (groupViewHolder == null) {
                throw new IllegalStateException("Bindings already cleared.");
            }
            this.target = null;
            groupViewHolder.layoutAll = null;
            groupViewHolder.ivGroupLeft = null;
            groupViewHolder.tvGroupName = null;
            groupViewHolder.tvDownloadAll = null;
            groupViewHolder.tvDownloadNumber = null;
            groupViewHolder.layoutDownloadItemAll = null;
            groupViewHolder.tvTitleGroup = null;
            groupViewHolder.tvSizeGroup = null;
            groupViewHolder.tvProgressGroup = null;
            groupViewHolder.progressGroup = null;
            groupViewHolder.tvStatusGroup = null;
            groupViewHolder.btnDownloadGroup = null;
        }
    }

    public ExpandableDownLoadAdapter(Context context, List<Download.NewItem> list) {
        this.context = context;
        this.downloadList = list;
    }

    public void setOnGroupItemClickListener(OnItemClickListener onItemClickListener) {
        this.onGroupItemClickListener = onItemClickListener;
    }

    public void setOnChildItemClickListener(OnItemClickListener onItemClickListener) {
        this.onChildItemClickListener = onItemClickListener;
    }

    @Override // android.widget.ExpandableListAdapter
    public int getGroupCount() {
        return this.downloadList.size();
    }

    @Override // android.widget.ExpandableListAdapter
    public int getChildrenCount(int i) {
        List<Download.NewItem> list = this.downloadList;
        if (list == null || list.size() <= 0 || this.downloadList.get(i).getItems() == null || this.downloadList.get(i).getItems().size() <= 0) {
            return 0;
        }
        return this.downloadList.get(i).getItems().size();
    }

    @Override // android.widget.ExpandableListAdapter
    public Object getGroup(int i) {
        return this.downloadList.get(i);
    }

    @Override // android.widget.ExpandableListAdapter
    public Object getChild(int i, int i2) {
        return this.downloadList.get(i).getItems().get(i2);
    }

    @Override // android.widget.ExpandableListAdapter
    public View getGroupView(final int i, boolean z, View view, ViewGroup viewGroup) {
        GroupViewHolder groupViewHolder;
        int parseInt;
        if (view == null) {
            view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_offline_download, viewGroup, false);
            groupViewHolder = new GroupViewHolder(view);
            view.setTag(groupViewHolder);
        } else {
            groupViewHolder = (GroupViewHolder) view.getTag();
        }
        if (this.downloadList.get(i).getItems().size() > 0) {
            groupViewHolder.layoutAll.setVisibility(0);
            groupViewHolder.layoutDownloadItemAll.setVisibility(8);
            groupViewHolder.tvDownloadAll.setVisibility(0);
            groupViewHolder.tvDownloadAll.setEnabled(true);
            groupViewHolder.tvDownloadAll.setOnClickListener(new View.OnClickListener() { // from class: com.gisocn.onemap.ui.adapter.ExpandableDownLoadAdapter.1
                @Override // android.view.View.OnClickListener
                public void onClick(View view2) {
                    if (ExpandableDownLoadAdapter.this.onGroupItemClickListener != null) {
                        ExpandableDownLoadAdapter.this.onGroupItemClickListener.onItemClick(view2, i);
                    }
                }
            });
            String notLoadNumber = this.downloadList.get(i).getNotLoadNumber();
            if (notLoadNumber != null && !TextUtils.isEmpty(notLoadNumber)) {
                if ("0".equals(notLoadNumber)) {
                    groupViewHolder.tvDownloadAll.setBackgroundResource(R.drawable.bg_black_radius5_storck);
                    groupViewHolder.tvDownloadAll.setTextColor(ContextCompat.getColor(this.context, R.color.colorBgGray));
                    groupViewHolder.tvDownloadAll.setEnabled(false);
                    groupViewHolder.tvDownloadAll.setText("全部完成");
                    groupViewHolder.tvDownloadNumber.setVisibility(4);
                } else {
                    groupViewHolder.tvDownloadAll.setBackgroundResource(R.drawable.bg_primary_radius5_storck);
                    groupViewHolder.tvDownloadAll.setTextColor(ContextCompat.getColor(this.context, R.color.colorPrimary));
                    groupViewHolder.tvDownloadAll.setEnabled(true);
                    groupViewHolder.tvDownloadAll.setText("下载全部");
                    groupViewHolder.tvDownloadNumber.setVisibility(0);
                }
            }
            groupViewHolder.tvDownloadNumber.setText(notLoadNumber);
            groupViewHolder.tvGroupName.setText(this.downloadList.get(i).getName());
            if (z) {
                groupViewHolder.ivGroupLeft.setImageDrawable(ContextCompat.getDrawable(this.context, R.mipmap.icon_arrow_down));
            } else {
                groupViewHolder.ivGroupLeft.setImageDrawable(ContextCompat.getDrawable(this.context, R.mipmap.icon_arrow_right));
            }
        } else {
            groupViewHolder.layoutAll.setVisibility(8);
            groupViewHolder.layoutDownloadItemAll.setVisibility(0);
            groupViewHolder.tvDownloadAll.setVisibility(8);
            groupViewHolder.tvDownloadNumber.setVisibility(8);
            groupViewHolder.tvTitleGroup.setText(this.downloadList.get(i).getName());
            TextView textView = groupViewHolder.tvSizeGroup;
            textView.setText(FormatSizeUtil.getFormatSize(Double.parseDouble(this.downloadList.get(i).getSize())) + "");
            groupViewHolder.btnDownloadGroup.setEnabled(true);
            groupViewHolder.btnDownloadGroup.setOnClickListener(new View.OnClickListener() { // from class: com.gisocn.onemap.ui.adapter.ExpandableDownLoadAdapter.2
                @Override // android.view.View.OnClickListener
                public void onClick(View view2) {
                    if (ExpandableDownLoadAdapter.this.onGroupItemClickListener != null) {
                        ExpandableDownLoadAdapter.this.onGroupItemClickListener.onItemClick(view2, i);
                    }
                }
            });
            groupViewHolder.tvProgressGroup.setText("");
            groupViewHolder.btnDownloadGroup.setVisibility(0);
            groupViewHolder.progressGroup.setVisibility(8);
            groupViewHolder.btnDownloadGroup.setBackgroundResource(R.drawable.bg_primary_radius5_storck);
            groupViewHolder.btnDownloadGroup.setTextColor(ContextCompat.getColor(this.context, R.color.colorPrimary));
            if (this.downloadList.get(i).getVersionDesc().equals("未下载")) {
                groupViewHolder.btnDownloadGroup.setText("下载");
            } else if (this.downloadList.get(i).getVersionDesc().equals("已是最新版本")) {
                groupViewHolder.tvStatusGroup.setText("已是最新版本");
                groupViewHolder.tvStatusGroup.setTextColor(ContextCompat.getColor(this.context, R.color.colorBlack));
                groupViewHolder.btnDownloadGroup.setText("已完成");
                groupViewHolder.btnDownloadGroup.setEnabled(false);
                groupViewHolder.btnDownloadGroup.setBackgroundResource(R.drawable.bg_black_radius5_storck);
                groupViewHolder.btnDownloadGroup.setTextColor(ContextCompat.getColor(this.context, R.color.colorBgGray));
            } else if (this.downloadList.get(i).getVersionDesc().equals("有更新版本")) {
                groupViewHolder.btnDownloadGroup.setText("更新");
                groupViewHolder.tvStatusGroup.setText("有更新版本");
            } else if (this.downloadList.get(i).getVersionDesc().equals("未完成")) {
                groupViewHolder.btnDownloadGroup.setText("下载");
                groupViewHolder.tvProgressGroup.setText("");
                groupViewHolder.progressGroup.setVisibility(0);
                groupViewHolder.progressGroup.setProgress(0);
            }
            TextView textView2 = groupViewHolder.tvStatusGroup;
            textView2.setText(this.downloadList.get(i).getVersionDesc() + "");
            groupViewHolder.progressGroup.setProgress(0);
            String currentLength = this.downloadList.get(i).getCurrentLength();
            groupViewHolder.btnDownloadGroup.setVisibility(0);
            groupViewHolder.progressGroup.setVisibility(4);
            if (currentLength != null && currentLength.length() > 0 && (parseInt = Integer.parseInt(currentLength)) > 0 && parseInt < 100) {
                groupViewHolder.tvStatusGroup.setText("下载中...");
                groupViewHolder.tvStatusGroup.setTextColor(ContextCompat.getColor(this.context, R.color.colorBlue));
                groupViewHolder.btnDownloadGroup.setVisibility(4);
                groupViewHolder.progressGroup.setVisibility(0);
                groupViewHolder.progressGroup.setProgress(Integer.parseInt(this.downloadList.get(i).getCurrentLength()));
            }
        }
        return view;
    }

    @Override // android.widget.ExpandableListAdapter
    public View getChildView(final int i, final int i2, boolean z, View view, ViewGroup viewGroup) {
        ChildViewHolder childViewHolder;
        int parseInt;
        if (view == null) {
            view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_offline_download, viewGroup, false);
            childViewHolder = new ChildViewHolder(view);
            view.setTag(childViewHolder);
        } else {
            childViewHolder = (ChildViewHolder) view.getTag();
        }
        childViewHolder.tvTitleChild.setText(this.downloadList.get(i).getItems().get(i2).getName());
        TextView textView = childViewHolder.tvSizeChild;
        textView.setText(FormatSizeUtil.getFormatSize(Double.parseDouble(this.downloadList.get(i).getItems().get(i2).getSize())) + "");
        childViewHolder.btnDownloadChild.setEnabled(true);
        childViewHolder.btnDownloadChild.setOnClickListener(new View.OnClickListener() { // from class: com.gisocn.onemap.ui.adapter.ExpandableDownLoadAdapter.3
            @Override // android.view.View.OnClickListener
            public void onClick(View view2) {
                if (ExpandableDownLoadAdapter.this.onChildItemClickListener != null) {
                    ExpandableDownLoadAdapter.this.onChildItemClickListener.onItemClick(view2, i, i2);
                }
            }
        });
        childViewHolder.tvProgressChild.setText("");
        childViewHolder.btnDownloadChild.setVisibility(0);
        childViewHolder.progressChild.setVisibility(8);
        childViewHolder.btnDownloadChild.setBackgroundResource(R.drawable.bg_primary_radius5_storck);
        childViewHolder.btnDownloadChild.setTextColor(ContextCompat.getColor(this.context, R.color.colorPrimary));
        if (this.downloadList.get(i).getItems().get(i2).getVersionDesc().equals("未下载")) {
            childViewHolder.btnDownloadChild.setText("下载");
        } else if (this.downloadList.get(i).getItems().get(i2).getVersionDesc().equals("已是最新版本")) {
            childViewHolder.tvStatusChild.setText("已是最新版本");
            childViewHolder.tvStatusChild.setTextColor(ContextCompat.getColor(this.context, R.color.colorBlack));
            childViewHolder.btnDownloadChild.setText("已完成");
            childViewHolder.btnDownloadChild.setEnabled(false);
            childViewHolder.btnDownloadChild.setBackgroundResource(R.drawable.bg_black_radius5_storck);
            childViewHolder.btnDownloadChild.setTextColor(ContextCompat.getColor(this.context, R.color.colorBgGray));
        } else if (this.downloadList.get(i).getItems().get(i2).getVersionDesc().equals("有更新版本")) {
            childViewHolder.btnDownloadChild.setText("更新");
            childViewHolder.tvStatusChild.setText("有更新版本");
        } else if (this.downloadList.get(i).getItems().get(i2).getVersionDesc().equals("未完成")) {
            childViewHolder.btnDownloadChild.setText("下载");
            childViewHolder.tvProgressChild.setText("");
            childViewHolder.progressChild.setVisibility(0);
            childViewHolder.progressChild.setProgress(0);
        }
        TextView textView2 = childViewHolder.tvStatusChild;
        textView2.setText(this.downloadList.get(i).getItems().get(i2).getVersionDesc() + "");
        childViewHolder.progressChild.setProgress(0);
        String currentLength = this.downloadList.get(i).getItems().get(i2).getCurrentLength();
        childViewHolder.btnDownloadChild.setVisibility(0);
        childViewHolder.progressChild.setVisibility(4);
        if (currentLength != null && currentLength.length() > 0 && (parseInt = Integer.parseInt(currentLength)) > 0 && parseInt < 100) {
            childViewHolder.tvStatusChild.setText("下载中...");
            childViewHolder.tvStatusChild.setTextColor(ContextCompat.getColor(this.context, R.color.colorBlue));
            childViewHolder.btnDownloadChild.setVisibility(4);
            childViewHolder.progressChild.setVisibility(0);
            childViewHolder.progressChild.setProgress(Integer.parseInt(this.downloadList.get(i).getItems().get(i2).getCurrentLength()));
        }
        return view;
    }

    /* loaded from: classes2.dex */
    static class GroupViewHolder {
        @BindView(R.id.btn_offline_download)
        TextView btnDownloadGroup;
        @BindView(R.id.iv_expand_group_arrow)
        ImageView ivGroupLeft;
        @BindView(R.id.layout_expand_group_all)
        LinearLayout layoutAll;
        @BindView(R.id.layout_offline_download_item_all)
        LinearLayout layoutDownloadItemAll;
        @BindView(R.id.progress)
        MyProgress progressGroup;
        @BindView(R.id.tv_expand_group_download_all)
        TextView tvDownloadAll;
        @BindView(R.id.tv_expand_group_number)
        TextView tvDownloadNumber;
        @BindView(R.id.tv_expand_group_title)
        TextView tvGroupName;
        @BindView(R.id.tv_progress)
        TextView tvProgressGroup;
        @BindView(R.id.tv_size)
        TextView tvSizeGroup;
        @BindView(R.id.tv_offline_download_status)
        TextView tvStatusGroup;
        @BindView(R.id.tv_title)
        TextView tvTitleGroup;

        GroupViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    /* loaded from: classes2.dex */
    static class ChildViewHolder {
        @BindView(R.id.btn_offline_download)
        TextView btnDownloadChild;
        @BindView(R.id.progress)
        MyProgress progressChild;
        @BindView(R.id.tv_progress)
        TextView tvProgressChild;
        @BindView(R.id.tv_size)
        TextView tvSizeChild;
        @BindView(R.id.tv_offline_download_status)
        TextView tvStatusChild;
        @BindView(R.id.tv_title)
        TextView tvTitleChild;

        ChildViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
